package com.fr.lintcode;

import java.util.Stack;

import org.junit.Test;

public class Q40ii {

	public class MyQueue {
        private Stack<Integer> stack1;
        private Stack<Integer> stack2;

        public MyQueue() {
            stack1 = new Stack<Integer>();
            stack2 = new Stack<Integer>();
        }

        public void push(int element) {
            stack1.push(element);
        }

        public int pop() {
        	if(stack2.isEmpty()){
        		while(!stack1.isEmpty()){
        			stack2.push(stack1.pop());
        		}
        	}
            return stack2.pop();
        }

        public int top() {
        	if(stack2.isEmpty()){
        		while(!stack1.isEmpty()){
        			stack2.push(stack1.pop());
        		}
        	}
            return stack2.peek();
        }
    }

    @Test
    public void testA() {
    	MyQueue q = new MyQueue();
        q.push(1);
        System.out.println(q.pop());
        q.push(2);
        q.push(3);
        System.out.println(q.top());
        System.out.println(q.pop());
    }
}
